#include <iostream>
#include <unistd.h>

int main()
{
    FILE *fd = fopen("log.txt", "a+");
    if (fd == nullptr)
    {
        std::cerr << "open log.txt fail!" << std::endl;
        return 1;
    }

    while (true)
    {
        std::cout << "test" << std::endl;
        fprintf(fd, "test\n");
        fflush(fd);
        sleep(1);
    }

    fclose(fd);
    return 0;
}